#!/bin/bash

DIR="$(dirname "$0")"

cmd=""
BootCmd=""
space=" "
update=0
show=0

if (( $# <= 0 )) ; then
	echo "V1.5.27"
	echo "Options:"
	echo "-s,--show                  Displag the current Boot Order."
	echo "--SetOrder=xx,xx,..     Explicitly set BootOrder(Decimal)."
	exit 1;
fi

for param in $*
do
	if test $param = "-s" -o $param = "--show" ;then
		BootCmd=$BootCmd$space$param
        show=1
    elif [[ $param =~ "--SetOrder=" && $param =~ .*[0-9].* ]] ;then
	    update=1
		BootCmd=$BootCmd$space$param
	else
		cmd=$cmd$space$param
	fi
done

if test -z "$BootCmd" ;then
	echo "Options:"
	echo "-s,--show                  Displag the current Boot Order."
	echo "--SetOrder=xx,xx,..     Explicitly set BootOrder(Decimal)."
	exit 1;
fi

if test $show = 1 -o ! -r "./config/config";then
	$DIR/SetupTool BootEx $cmd
fi
bash $DIR/kltool_bootcfg.sh $BootCmd
if [ $? -ne 0 ]; then
	exit 1
fi

if [ "$update" -ne "0" ] ;then
	$DIR/SetupTool import $cmd
fi

exit $?
